<?php
/**
 * Template Name: Draft Priview
 *
 * @GramediaWritingProject
 * @version 1.0
 * @Epifana & Vincentia
 */
 if (!is_user_logged_in()){wp_redirect(get_site_url());}
get_header(); 

$chapter_id= isset( $_GET['pid'] ) ? intval( $_GET['pid'] ) : 0;
	$bookid = isset( $_GET['bookid'] ) ? intval( $_GET['bookid'] ) : 0;
	$book = get_post($bookid);
	$content = $book->post_content;
	$title = $book ->post_title;
	$mykey_values = get_post_custom_values( 'Chapter' ); 
	if ($chapter_id!=0){
			$lala=get_post($chapter_id);
			$ctitle = $lala->post_title;
			$ccontent=$lala->post_content;
			
	}?>

    <div class="col-md-12 column content">
	<div class="row clearfix">
	


		<?php //if( have_posts() ) : while ( have_posts() ) : the_post(); ?>
		<?php get_template_part( 'kolompertama' ); ?>
	
		<div class="col-md-9 column" > <!-- untuk kolom kedua yang dibagi 2 -->
			<div class="row clearfix">
									
				<div class="col-md-12 column">
				
                	<!-- start cerita -->
                    <div>
					
                        <br/>
                        <h9> (konsep)
                            <?php if ($chapter_id!=0) {echo $title;echo " - " . $ctitle;} else {echo $title; }?> 
                        </h9>
                        <hr/>
                        <table style="width:100%" id="tablepager">
                            <tr>
                                <td style="width:30%">
							<?php	$mykey_values = get_post_meta( $bookid, 'Chapter' );
?>								<form name="selectpart" >
							   	<?php  
									if (count($mykey_values) >0){
									$sort = array();
									$idbab = array();
                                foreach ( $mykey_values as $key => $babid ) 
										{
											$number = get_post_meta($babid, 'number', true);//get_post_custom_values ( 'number', $babid);
											array_push($sort, (int)$number);
											array_push($idbab, $babid);
										}
										//sorting chapter berdasarkan urutan (number)
											array_multisort($sort,$idbab); ?>
											<select  class="selectBox" onchange =" window.open( this.options[ this.selectedIndex ].value, '_self')" name="part" width="300px">
								<?php	if ($chapter_id==0){
												echo "<option >&nbsp;&nbsp;Silakan pilih bab&nbsp;&nbsp;&nbsp;&nbsp;</option>";
																							
												} 
										else {
										echo '<option value="?bookid='.$bookid.'">SINOPSIS</option>';
											
											}
											 foreach ( $idbab as $sortedid => $babidsorted )
											{
											  $chapter = get_post($babidsorted);
												$title = $chapter->post_title;
												$content = $chapter -> post_content;
												$link = "?bookid=".$bookid."&pid=".$babidsorted . "&" .$title;
												
											  if ($chapter_id==$babidsorted)
											  {	echo "<option selected='selected' 'value='".$link."'>".$title."</value>";
													}
												else {		echo "<option value='".$link."'>".$title."</value>";}
												
											}
										} 
											?>
								
																	
                                      </select>
									   </div>
									 </form>
										

                                </td>
								
                         
                            </tr>
                        </table>
                        
                        <br/>
                        <div id="paper"></div> 
                        <div id="page"> 
						
                       <div class="paragrafcerita" id="text-pager"><!--ini yang bikin gagal pagination nya jadi harus tambah div-->
					   <div><?php if ($chapter_id!=0) {  echo wpautop($ccontent) ;
				
					  }
					   else { ?> <h7>SINOPSIS</h7><br/> <hr/>
					   <?php echo wpautop($content);}?> </div></div>
						<div class="controls" >
						<a class="tp-control-arrow-left unactive" href="#tablepager"><span>Prev</span></a>
						<a class="tp-control-arrow-right" href="#tablepager"><span>Next</span></a>
						<ul class="pager222">
						</ul>
						</div>
						<script>
						//$(window).load(function(){
						$('#text-pager').textpager({
						controlArrows: ".controls",
						controlPages: ".controls .pager222",
						controlPagesContent: "li",
						
						});//});
						$('.tp-page').attr("href") = "#";
				
						</script>
						<br/>
					   </div>
                    </div>
          
                    <div class="clearfix"></div>
                    <hr/>

                    <br/>
				
                 
                    <!-- stop cerita -->
                </div>
            </div>
		</div> <!-- end kolom kedua -->
		
       </div><!-- end row clearfix -->
</div> <!--end col-md-12 column content-->
	<!-- end untuk content -->
     <!-- untuk iklan -->
	
    
    <!-- untuk footer -->
	<?php
get_footer();
?>